package com.aiguigu.test;





import java.util.*;

public class Code {
    public static void main(String[] args) {
        String string = "nddemdereeeffetcssssfggddregg";
        char[] bytes = string.toCharArray();
        Map<Character, Integer> counts = new HashMap<>();
        for (char b : bytes) {
            Integer count = counts.get(b);
            if (count == null){
                counts.put(b,1);
            }else {
                counts.put(b,count+1);
            }
        }
        List<Node> list = new ArrayList<>();
        for (Map.Entry<Character,Integer> entry:counts.entrySet()) {
            Node node = new Node(entry.getKey(),entry.getValue());
            list.add(node);
        }

        Node node = list.stream().max(new Comparator<Node>() {
            @Override
            public int compare(Node o1, Node o2) {
                return o1.getCount()-o2.getCount() ;
            }
        }).get();

        System.out.println(node);


    }

}

class Node {
    private Character character;
    private Integer count;

    public Character getCharacter() {
        return character;
    }

    public void setCharacter(Character character) {
        this.character = character;
    }

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public Node(Character character, Integer count) {
        this.character = character;
        this.count = count;
    }

    @Override
    public String toString() {
        return "Node{" +
                "character=" + character +
                ", count=" + count +
                '}';
    }
}
